import { Inject, Injectable } from "@nestjs/common";
import { CreateRediDto } from "./dto/create-redi.dto";
import { UpdateRediDto } from "./dto/update-redi.dto";
import { Cache } from "cache-manager";
import { CACHE_MANAGER } from "@nestjs/cache-manager";
@Injectable()
export class RedisService {
	private USRE_KEY = "user_key:";
	constructor(
		@Inject(CACHE_MANAGER)
		private cacheManager: Cache
	) {}

	async create(createRediDto: CreateRediDto) {
		const cacheId = new Date().getTime();
		await this.cacheManager.set(
			this.USRE_KEY + cacheId,
			createRediDto,
			1000 * 60 * 60 // ttl必须
		);
		return {
			cacheId,
			...createRediDto
		};
	}

	findAll() {
		return `This action returns all redis`;
	}

	findOne(id: number) {
		return `This action returns a #${id} redi`;
	}

	update(id: number, updateRediDto: UpdateRediDto) {
		return `This action updates a #${id} redi with ${updateRediDto}`;
	}

	remove(id: number) {
		return `This action removes a #${id} redi`;
	}
}
